﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TZReport_Model.DBModel;
using TZReport_Util.Basic;
using TZReport_Util.Util;

namespace TZRerport_Dal.Dal
{
    public abstract class BaseTJDal
    {
        public SqlHelper sqlHelper = new SqlHelper(ConfigManager.conn);

        public Func<string, string> GetTiJianBModelSql;

        public abstract void SetQuertSql();

        public BaseTJDal()
        {
            SetQuertSql();
        }

        public List<TiJianBModel> GetTiJianBModelList()
        {
            string sql = GetTiJianBModelSql(string.Empty);
            List<TiJianBModel> list = sqlHelper.GetData<TiJianBModel>(sql, System.Data.CommandType.Text);
            return list;
        }

        public List<TiJianBModel> GetTiJianBModelList(int num)
        {
            string msg = $" TOP {num} ";
            string sql = GetTiJianBModelSql(msg);

            List<TiJianBModel> list = sqlHelper.GetData<TiJianBModel>(sql, System.Data.CommandType.Text);
            return list;
        }

        public List<string> GetTiJianBHList(string satrtDate, string endDate, int status)
        {
            string sql = $@"SELECT physical_no FROM TZ_Report_Record WHERE report_date>='{satrtDate}' AND report_date<='{endDate}' AND status={status}";
            DataTable dt = sqlHelper.GetData(sql, System.Data.CommandType.Text);
            List<string> listTJH = new List<string>();
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    string physicalNo = row[0].ToString();
                    listTJH.Add(physicalNo);
                }
            }

            return listTJH;
        }
    }
}
